package com.quartz.tasks.job;

import com.quartz.tasks.web.service.RestTemplateService;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 彭长云
 * @Description:测试
 * @date 2018/12/5 14:48
 */
public class TestJob implements Job,Serializable{

    @Autowired
    private RestTemplateService rt;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
        System.out.println("*****************" + dataMap.get("data"));
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(new Date()) + "com.quartz.tasks.job.TestJob执行");
        try {
            String url="http://localhost/task/hello";
            String requestJson = "{\"age\":22}";
            rt.post(url,requestJson);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
